home *** CD-ROM | disk | FTP | other *** search
/ Libris Britannia 4 / science library(b).zip / science library(b) / PROGRAMM / CC_C / 0924.ZIP / HDUMP < prev    next >
Text File  |  1988-01-10  |  3KB  |  95 lines

  1.  
  2. /*      -----    C PROGRAM FOR FILE DUMP    -----
  3.          Command Line: HDUMP FILENAME \n
  4. */
  5.  
  6. /* Standard IO definitions */
  7. #define         NULL      0
  8. #define         EOF      -1
  9. #define         ERROR    -1
  10.  
  11. /* IO buffer size */
  12. #define        qbsize  8192
  13.  
  14. /* Global output line buffer */
  15. char line[80], *ptr;
  16.  
  17. /* Read    and dump file */
  18. main (argc, argv) int argc; int    *argv;
  19.  
  20.     {  static int i, c, d, r, cc[16];
  21.        static unsigned ic;
  22.        static char *afile;
  23.        static char *qnx, *qnd; static int qfd;
  24.        static char qbb [qbsize];
  25.  
  26.        putstr ("\n    C FILE DUMP PROGRAM\n\n");
  27.  
  28.        if (argc < 2)
  29.        {  putstr ("     NO FILE SPECIFIED.\n"); return; }
  30.        if (    (qfd = open (afile = *++argv, 0)) == ERROR)
  31.        {  putstr ("     CANNOT    OPEN FILE ");
  32.           putstr (afile); putstr ("\n"); return; }
  33.  
  34.        for (qnx = qnd = qbb, ic = 0x100; ; ic++)
  35.        {
  36.           if (qnx <    qnd) c = *qnx++;
  37.           else  {  qnd = qbb + read    (qfd, qbb, qbsize);
  38.                c = ((qnx = qbb)    < qnd) ? *qnx++    : EOF; }
  39.           cc [r = ic % 16] = c;
  40.  
  41.           if (r == 0)
  42.           {     if (c == EOF) break; ptr = line; sp (2);
  43.          hex (ic >> 8);    hex (ic    & 0xFF);  sp (1); }
  44.  
  45.           if (c == EOF) sp (3);
  46.           else { *ptr++ = (r == 8) ? '-' : ' '; hex    (c); }
  47.  
  48.           if ( r ==    15)
  49.           {     sp (2);
  50.          for (i    = 0; i < 16; i++)
  51.          {  if ((d = cc[i]) == EOF) sp (1);
  52.             else *ptr++    = (d < 0x20 || d > 0x7F) ? '.' : d; }
  53.          *ptr++    = '\n';    *ptr = 0; putstr (line); }
  54.          }
  55.  
  56.         close (qfd); }
  57.  
  58.  
  59. hex (n)    unsigned n; { dig (n >>    4);  dig (n & 0xF); }
  60. dig (n)    unsigned n; { *ptr++ = '0' + n + (n > 9    ? 7 : 0); }
  61. sp (n)    { while    (n--) *ptr++ = ' '; }
  62.  
  63.  
  64. /* File    and Console Input/Output */
  65.  
  66. /* Put string to stdout    - MSDOS    Fn 6 except for    \n. */
  67. putstr (s) char    *s;
  68.      {    inline ( 0x89, 0xE5, 0x8B, 0x7E, 0x02, 0x31, 0xDB,
  69.          0x8A, 0x05, 0x47, 0x08, 0xC0, 0x74, 0x1B,
  70.          0x43, 0x3C, 0x0A, 0x74, 0x08, 0x88,
  71.          0xC2, 0xB4, 0x06, 0xCD, 0x21, 0xEB, 0xEC,
  72.          0xB2, 0x0D, 0xB4, 0x02, 0xCD, 0x21,
  73.          0xB2, 0x0A, 0xB4, 0x02, 0xCD, 0x21, 0xEB, 0xDE    ); }
  74.  
  75. open (name, mode) char *name;
  76.      {    /* Modes 0 read, 1 write, 2 r/w    */
  77.     inline ( 0x89, 0xE5, 0x8B, 0x56, 0x04, 0x8A, 0x46, 0x02,
  78.          0xB4, 0x3D, 0xCD, 0x21, 0x89, 0xC3,
  79.          0x73, 0x03, 0xBB, 0xFF, 0xFF ); }
  80.  
  81. close (fd)
  82.      {    inline ( 0x89, 0xE5, 0x8B, 0x5E, 0x02,
  83.          0xB4, 0x3E, 0xCD, 0x21, 0xBB, 0x00, 0x00,
  84.          0x73, 0x03, 0xBB, 0xFF, 0xFF ); }
  85.  
  86. read (fd, buf, ct) char    *buf;
  87. /* returns #read, else 0 EOF or    -1 error */
  88.      {    inline ( 0x89, 0xE5, 0x8B, 0x5E, 0x06,
  89.          0x8B, 0x56, 0x04, 0x8B, 0x4E, 0x02,
  90.          0xB4, 0x3F, 0xCD, 0x21, 0x89, 0xC3,
  91.          0x73, 0x03, 0xBB, 0xFF, 0xFF ); }
  92.  
  93. /* End of dump file program */
  94.  
  95.